package com.flyduck.service.impl;

import com.flyduck.domain.SysJob;
import com.flyduck.mapper.SysJobMapper;
import com.flyduck.service.SysJobService;
import com.flyduck.vo.PageResult;
import com.flyduck.vo.QueryVo;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: flyduck-admin
 * @description:
 * @author: flyduck
 * @create: 2020-05-06 14:03
 **/
@Service
public class SysJobServiceImpl implements SysJobService {

    @Autowired
    private SysJobMapper sysJobMapper;

    @Override
    public List<SysJob> findList() {
        return sysJobMapper.findList();
    }

    /**
     * 分页数据
     * @param queryVo
     * @return
     */
    @Override
    public PageResult findPage(QueryVo queryVo) {
        //分页查询
        PageHelper.startPage(queryVo.getPage(),queryVo.getRows());
        Page<SysJob> sysJobPage = sysJobMapper.findPage(queryVo.getKeyword());
        //分页结果集
        PageResult pageResult = new PageResult();
        pageResult.setTotal(sysJobPage.getTotal());
        pageResult.setRows(sysJobPage.getResult());
        return pageResult;
    }

    /**
     * 保存岗位
     * @param sysJob
     */
    @Override
    public void save(SysJob sysJob) {
        sysJobMapper.insertSelective(sysJob);
    }

    /**
     * 更新岗位
     * @param sysJob
     */
    @Override
    public void update(SysJob sysJob) {
        sysJobMapper.updateByPrimaryKeySelective(sysJob);
    }

    /**
     * 根据id查询岗位
     * @param id
     * @return
     */
    @Override
    public SysJob getJobById(Long id) {
        return sysJobMapper.getJobById(id);
    }

    /**
     * 启用/禁用岗位
     * @param id
     * @param enabled
     */
    @Override
    public void updateStatus(Long id, Boolean enabled) {
        sysJobMapper.updateStatus(id,enabled);
    }


}
